//
//  PKListTableViewCell.m
//  ShrimpCrowdordering
//
//  Created by 郑洲 on 2018/7/30.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "PKListTableViewCell.h"

@interface PKListTableViewCell ()


@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UIButton *otherPraise;
@property (nonatomic, strong) UIButton *myPraise;
@property (nonatomic, strong) UILabel *stateLabel;

@property (nonatomic, strong) UIImageView *otherView;
@property (nonatomic, strong) UIImageView *myView;

@end

@implementation PKListTableViewCell

+ (PKListTableViewCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"PKListTableViewCell";
    PKListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[PKListTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = TABLEVIEW_BACKGROUNDCOLOR;
        [cell createSubView];
    }
    
    return cell;
}

- (void)createSubView {
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(23), ScreenX375(110), ScreenX375(13))];
    self.timeLabel.textColor = FONTCOLOR_BLACK;
    self.timeLabel.font = Kfont(13);
    self.timeLabel.text = @"2018-6-15";
    [self addSubview:self.timeLabel];
    
    self.otherPraise = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(126), ScreenX375(20), ScreenX375(50), ScreenX375(15))];
    [self.otherPraise setImage:ImageWithName(@"Combined Shape Copy") forState:UIControlStateNormal];
    [self.otherPraise setTitle:@"256" forState:UIControlStateNormal];
    [self.otherPraise setTitleColor:FONTCOLOR_BLACK forState:UIControlStateNormal];
    self.otherPraise.titleLabel.font = Kfont(13);
    [self.otherPraise setTitleEdgeInsets:UIEdgeInsetsMake(0, -WIDTH(self.otherPraise.imageView), 0, WIDTH(self.otherPraise.imageView))];
    [self.otherPraise setImageEdgeInsets:UIEdgeInsetsMake(0, WIDTH(self.otherPraise.titleLabel), 0, -WIDTH(self.otherPraise.titleLabel))];
    [self addSubview:self.otherPraise];
    
    self.myPraise = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(197), ScreenX375(20), ScreenX375(50), ScreenX375(15))];
    [self.myPraise setImage:ImageWithName(@"Combined Shape") forState:UIControlStateNormal];
    [self.myPraise setTitle:@"256" forState:UIControlStateNormal];
    [self.myPraise setTitleColor:FONTCOLOR_BLACK forState:UIControlStateNormal];
    self.myPraise.titleLabel.font = Kfont(13);
    [self.myPraise setTitleEdgeInsets:UIEdgeInsetsMake(0, -WIDTH(self.myPraise.imageView), 0, WIDTH(self.myPraise.imageView))];
    [self.myPraise setImageEdgeInsets:UIEdgeInsetsMake(0, WIDTH(self.myPraise.titleLabel), 0, -WIDTH(self.myPraise.titleLabel))];
    [self addSubview:self.myPraise];
    
    self.stateLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(344), ScreenX375(21), ScreenX375(15), ScreenX375(15))];
    self.stateLabel.text = @"赢";
    self.stateLabel.font = Kfont(15);
    self.stateLabel.textAlignment = NSTextAlignmentCenter;
    self.stateLabel.textColor = FONTCOLOR_BLACK;
    [self addSubview:self.stateLabel];
    
    self.otherView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(209), ScreenX375(48), ScreenX375(150), ScreenX375(150))];
    self.otherView.image = ImageWithName(@"4");
    self.otherView.layer.cornerRadius = ScreenX375(6);
    self.otherView.clipsToBounds = YES;
    self.otherView.contentMode = UIViewContentModeScaleAspectFill;
    [self addSubview:self.otherView];
    
    UILabel *vsLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(176), ScreenX375(109), ScreenX375(24), ScreenX375(24))];
    vsLabel.text = @"VS";
    vsLabel.textAlignment = NSTextAlignmentCenter;
    vsLabel.font = Kfont(18);
    vsLabel.textColor = FONTCOLOR_BLACK;
    [self addSubview:vsLabel];
    
    self.myView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(48), ScreenX375(150), ScreenX375(150))];
    self.myView.image = ImageWithName(@"5");
    self.myView.layer.cornerRadius = ScreenX375(6);
    self.myView.clipsToBounds = YES;
    self.myView.contentMode = UIViewContentModeScaleAspectFill;
    [self addSubview:self.myView];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(217.5), SCREEN_WIDTH - ScreenX375(16), ScreenX375(0.5))];
    line.backgroundColor = REXADECIMALCOLOR(@"#f2f2f2");
    [self addSubview:line];
}

- (void)setPkListModel:(PkListModel *)pkListModel {
    _pkListModel = pkListModel;
    
    self.timeLabel.text = [NSString stringWithFormat:@"%@",pkListModel.createTime];
    [self.otherPraise setTitle:pkListModel.acceptorZan forState:UIControlStateNormal];
    [self.myPraise setTitle:pkListModel.initiatorZan forState:UIControlStateNormal];
    self.stateLabel.text = pkListModel.result;
    if ([pkListModel.result isEqualToString:@"赢"]) {
        self.stateLabel.textColor = REXADECIMALCOLOR(@"#f21934");
    }else {
        self.stateLabel.textColor = REXADECIMALCOLOR(@"#34a7ff");
    }
    [self.otherView sd_setImageWithURL:[NSURL URLWithString:pkListModel.acceptorPic] placeholderImage:nil options:SDWebImageRetryFailed];
    [self.myView sd_setImageWithURL:[NSURL URLWithString:pkListModel.initiatorPic] placeholderImage:nil options:SDWebImageRetryFailed];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

@implementation PkListModel

+(JSONKeyMapper*)keyMapper
{
    return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{
                                                                  @"Id": @"id"
                                                                  }];
}


@end
